#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery
            , form = layui.form;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: 'true'}
                , {field: 'name', title: '架构名称', minWidth: 150,sort:true}
                , {field: 'belongToName', title: '所属组织', minWidth: 150,sort:true}
                , {field: 'createTime', title: '创建时间', minWidth: 180,sort:true}
                // , {field: 6, title: '状态', width: 100}
                , {fixed: 'right', title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption'}
            ]]
            , url: '#(ctxPath)/app/OrgStructure/searchStructureApi'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });
        table.on('tool(dateTable)', function(obj) {
            var data = obj.data;
            if (obj.event === 'add') {
                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/OrgStructure/joinStructureApi',
                    data: {structID: data.id},
                    loadFlag: true,
                    success: function (data) {
                        reloadTable($('#name').val());
                        //layer.msg("加入架构申请已经成功，请耐心等待！");
                    }
                });
            }
        });
        //查找数据 表格重载
        reloadTable = function (name,sid) {
            table.reload('dateTable', {
                url: '#(ctxPath)/app/OrgStructure/searchStructureApi'
                , where: {name: name,sid: sid} //设定异步数据接口的额外参数
            });
        }
        form.on('submit(search)', function(data){
             reloadTable(data.field.name,data.field.sid);
             return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
         });
        //监听两个输入框不能同时输入数据
        $("#name").click(function(){
            $("#sid").val("");
        });
        $("#sid").click(function(){
            $("#name").val("");
        });
    });

</script>
#end

#define content()
<div class="layui-fluid">
    <form id="searchForm" class="layui-form x-center" action="" >
        <div class="layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">架构名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" placeholder="架构名称" class="layui-input"/>
                </div>

                <label class="layui-form-label">架构ID</label>
                <div class="layui-input-inline">
                    <input type="number" id="sid" name="sid" placeholder="架构ID" class="layui-input"/>
                </div>

                <div class="layui-input-inline" style="width : 80px">
                    <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
    <hr>
    <div class="layui-row">
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add">申请加入</a>
</script>
#end